/**
* 培训查看
*/
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>课程管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="conditionData" class="user-search">
      <el-form-item label="">
        <el-input size="small" v-model="conditionData.courseTitle" placeholder="课程名称"></el-input>
      </el-form-item>
      <el-form-item label="">
        <el-input size="small" v-model="conditionData.courseGrade" placeholder="课程等级"></el-input>
      </el-form-item>
      <el-select v-model="conditionData.managerId" clearable filterable placeholder="负责人">
        <el-option v-for="item in selectdata" :key="item.managerId" :label="item.managerName" :value="item.managerId">
        </el-option>
      </el-select>
      <el-select v-model="conditionData.trainId" clearable filterable placeholder="课程分类">
        <el-option v-for="item in selectdatatrain" :key="item.trainId" :label="item.trainName" :value="item.trainId">
        </el-option>
      </el-select>
      <el-select v-model="conditionData.courseStatus" clearable filterable placeholder="课程状态">
        <el-option v-for="item in selectdatastatus" :key="item.courseStatus" :label="item.courseStatusName"
          :value="item.courseStatus">
        </el-option>
      </el-select>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
        <el-button router :default-active="$route.path" size="small" type="primary" icon="el-icon-plus"
          @click="handleEdit()">添加

        </el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table size="small" @selection-change="selectChange" :data="courseData" highlight-current-row v-loading="loading"
      border element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column align="center" sortable prop="courseTitle" label="课程名称" width="220">
      </el-table-column>
      <el-table-column align="center" sortable prop="trainName" label="课程类别" width="220">
      </el-table-column>
      <el-table-column align="center" sortable prop="courseGrade" label="课程等级" width="220">
      </el-table-column>
      <el-table-column align="center" sortable prop="courseStatus" label="课程状态" width="220">
      </el-table-column>
      <el-table-column align="center" sortable prop="managerName" label="负责人" width="220">
      </el-table-column>
      <el-table-column align="center" sortable prop="courseTime" label="课时" width="220">
      </el-table-column>

      <el-table-column label="操作" min-width="300">
        <template slot-scope="scope">
          <el-button size="mini">
            <router-link :to="{path:'/courseEdit/'+scope.row.id}">编辑</router-link>

          </el-button>
          <el-button size="mini" type="danger" @click="deleteUser(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:childMsg="pageparm" @callFather="callFather"></Pagination>
  </div>
</template>

<script>
  import Pagination from '../../components/Pagination'
  import router from '../../router/index.js'

  export default {
    data() {
      return {
        loading: false, //是显示加载
        title: '添加用户',
        // 编辑与添加
        editForm: {
          userId: '',
          userName: '',
          userRealName: '',
          roleId: '',
          userMobile: '',
          userEmail: '',
          userSex: '',
          token: localStorage.getItem('logintoken')
        },
        // 选择数据
        // 负责人的数组
        selectdata: [],
        // 课程分类的数组
        selectdatatrain: [],
        // 课程状态的数组
        selectdatastatus: [],

        // 请求数据参数
        formInline: {
          page: 1,
          limit: 10,
        },
        //搜索条件
        conditionData: {
          //  课程名称
          courseTitle: '',
          // 课程等级
          courseGrade: '',
          // 负责人
          managerId: "",
          //  课程分类
          trainId: '',
          // 课程状态
          courseStatus: ''
        },
        //课程数据
        courseData: [],
        // 数据权限
        UserDept: [],
        defaultProps: {
          children: 'children',
          label: 'name'
        },
        //参数role
        // 分页参数
        pageparm: {
          currentPage: 1,
          pageSize: 5,
          total: 10
        }
      }
    },
    // 注册组件
    components: {
      Pagination
    },

    /**
     * 数据发生改变
     */
    watch: {},

    /**
     * 创建完毕
     */
    created() {
      this.getdata(this.formInline)
    },

    /**
     * 里面的方法只有被调用才会执行
     */
    methods: {
      // 获取数据方法
      getdata(parameter) {
        this.loading = true
        /***
         * 调用接口，注释上面模拟数据 取消下面注释
         */
        this.pageparm.currentPage = this.formInline.page
        this.pageparm.pageSize = this.formInline.limit
        // 获取培训列表
        this.$axios.post('/api/course/courseManage/' + this.pageparm.currentPage + '/' + this.pageparm.pageSize, this
            .conditionData)
          .then(res => {
            console.log(res)
            this.loading = false
            if (res.data.code === 200) {
              this.$message({
                type: 'info',
                message: res.data.message
              })
              this.courseData = res.data.data.list
              this.pageparm.total = res.data.data.total
            }
          }),
          this.$axios.get('/api/course/courseManage/condition').then(res => {
            console.log(res);
            if (res.data.code === 200) {
              console.log(res.data.data);
              this.selectChange(res.data.data)
            }
          })
      },
      // 分页插件事件
      callFather(parm) {
        console.log(parm)
        this.formInline.page = parm.currentPage
        this.formInline.limit = parm.pageSize
        this.getdata(this.formInline)
      },
      //搜索事件
      search() {
        this.getdata(this.formInline)
      },
      //显示编辑界面
      handleEdit: function (index, row) {
        // this.editFormVisible = true
        this.$router.push({
          path: '/courseEdit/-1'
        })
      },
      // 选择复选框事件
      selectChange(val) {
        this.selectdata = val.managerNameDtos
        this.selectdatatrain = val.trainDtos
        this.selectdatastatus = val.courseStatusDtos
      },


    }
  }

</script>

<style scoped>
  .user-search {
    margin-top: 20px;
  }

  .userRole {
    width: 100%;
  }

</style>
